package com.itheima.demo;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class JDK8DateDemo5 {
    /*
    public String format (指定格式)把一个LocalDateTime格式化成为一个字符串
    public LocalDateTime parse (准备解析的字符串, 解析格式)把一个日期字符串解析成为一个LocalDateTime对象
    public static DateTimeFormatter ofPattern(String pattern)使用指定的日期模板获取一个日期格式化器DateTimeFormatter对象
     */
    public static void main(String[] args) {
        LocalDateTime localDateTime = LocalDateTime.of(2020, 12, 12, 13, 14, 15);
        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH-mm-ss");
        String s = localDateTime.format(pattern);
        System.out.println(s);

        String ss = "2020-12-12 13-14-15";
        LocalDateTime parse = LocalDateTime.parse(ss, pattern);
        System.out.println(parse);
        LocalDateTime localDateTime1 =LocalDateTime.now();
        System.out.println(localDateTime1);
    }

}
